package com.example.teacher

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.example.teacher.databinding.ActivityAddCourseBinding
import com.example.teacher.http.OkHttp

/**
 * 添加课程
 */
class AddCourseActivity : AppCompatActivity() {

    lateinit var binding:ActivityAddCourseBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_course)

        binding=DataBindingUtil.setContentView(this,R.layout.activity_add_course)
        binding.btnAddCourse.setOnClickListener {
            val courseId=binding.editTextCourseId.text
            val courseName=binding.editTextCourseName.text
            val teacher=binding.editTextTeacher.text
            val courseNum=binding.editTextCourseNum.text
            val classHours=binding.editTextCalssHours.text

            val resData = OkHttp.getSync(
                "${BaseUrl.URL}${BaseUrl.NEW_COURSE}" +
                        "?courseId=${courseId}" +
                        "&courseName=${courseName}" +
                        "&teacher=${teacher}" +
                        "&courseNum=${courseNum}" +
                        "&classHours=${classHours}"
            )
            if (resData.equals("1")){
                Toast.makeText(this,"创建成功",Toast.LENGTH_SHORT).show()
                finish()
            }else
                Toast.makeText(this,"创建失败",Toast.LENGTH_SHORT).show()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
    }


}